<template>
  <div class="header">
    <div class="header-page">
      <div class="header-left" @click="onClickLeft"><van-icon name="arrow-left" /></div>
      <div class="header-title">{{title}}</div>
      <div v-if="rightText" class="header-right" @click="onClickRight">{{rightText}}</div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CDWHeader',
  props: {
    title: String,
    rightText: String,
  },
  created(){
  },
  methods: {
    onClickLeft(){
      if(this.$route.name == 'acknowledgementOfOrder'){
        this.$router.push({
          name: 'productDetail',
          query: {
            id: this.$route.query.goodsId
          }
        });
      }else if(this.$route.name == 'productDetail'){
        this.$router.push({
          name: 'indexHome',
          query: {
            token: this.$utils.SessionGet('token')
          }
        });
      }else{
        this.$router.go(-1)
      }
    },
    onClickRight(event) {
      this.$emit('click-right', event);
    },
  }
}
</script>
<style scoped lang="less">
@height: 48px;
.header{
  height: @height + 1;
  &-page{
    display: flex;
    width: 100%;
    height: @height;
    line-height: @height;
    position: fixed;
    background: #fff;
    text-align: center;
    border-bottom: 1px solid #ebedf0;
    z-index: 10;
  }
  &-title{
    font-size: 18px;
    font-weight: 700;
    flex: 1;
  }
  &-left{
    position: absolute;
    left: 0;
    padding: 0 12px;
    font-size: 21px;
    font-weight: 700;
  }
  &-right{
    position: absolute;
    right: 0;
    color: #51AFB1;
    padding: 0 18px;
  }
}
</style>
